package com.zy.openchat.core.model.group;

import com.ja.openchat.ui.chat.group.GroupSendManager;
import com.zy.openchat.core.model.message.ChatInfo;
import com.zy.openchat.core.model.message.ChatType;
import com.zy.openchat.core.model.user.UserInfo;
import com.zy.openchat.util.Common;

import java.io.Serializable;
import java.util.ArrayList;


public class GroupSendInfo implements Serializable {
    public static final String CHAT_TYPE_FOR_GROUP_SEND = "chatTypeGroupSend";

    public long id;

    public ArrayList<Long> userIds;

    public LocalMessageInfo messageInfo;

    public GroupSendInfo(ArrayList<Long> userIds) {
        this.userIds = userIds;
        this.id = GroupSendManager.getInstance().createGroupSendId();
    }

    public int groupNumber(){
        return Common.isEmpty(userIds)?0:userIds.size();
    }

    public String userNames(){
        if(Common.isEmpty(userIds)){
            return "";
        }
        StringBuilder builder = new StringBuilder();
        for(Long userId:userIds){
            UserInfo userInfo = UserInfo.getUserInfo(userId);
            if(userInfo!=null){
                builder.append(userInfo.displayName());
                builder.append("、");
            }
        }
        return builder.length()>0?builder.substring(0,builder.length()-1):builder.toString();
    }

    public ChatInfo buildChat(){
        ChatInfo chatInfo = new ChatInfo();
        chatInfo.id = id;
        ChatType chatType = new ChatType();
        chatType.type = CHAT_TYPE_FOR_GROUP_SEND;
        chatInfo.type = chatType;
        chatInfo.title = "群发";
        chatInfo.group_uers = userIds;
        return chatInfo;
    }



    public boolean isEmpty(){
        return Common.isEmpty(userIds);
    }

}
